package com.gxuwz.Market.business.action.web;

import java.sql.Timestamp;
import java.util.Date;
import java.util.Random;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;

import com.gxuwz.Market.business.entity.ServiceStudio;
import com.gxuwz.Market.business.service.IServiceStudioService;
import com.gxuwz.core.pagination.Result;
import com.gxuwz.core.web.action.BaseAction;
import com.opensymphony.xwork2.ModelDriven;
import com.opensymphony.xwork2.Preparable;

public class ServiceStudioAction extends BaseAction implements Preparable, ModelDriven<ServiceStudio> {

	protected static final String LIST_JSP = "/WEB-INF/page/web/ServiceStudio_list.jsp";  
	protected static final String ADD_JSP = "/WEB-INF/page/web/ServiceStudio_add.jsp";
	protected static final String EDIT_JSP = "/WEB-INF/page/web/ServiceStudio_edit.jsp";
	
	@Autowired
	private IServiceStudioService serviceStudioService;
	
	private ServiceStudio serviceStudio;
	private Result<ServiceStudio> pageResult;
	
	
	
	@Override
	public void prepare() throws Exception {
		if(null == serviceStudio){
			serviceStudio = new ServiceStudio();
		}
	}

	@Override
	public ServiceStudio getModel() {
		return serviceStudio;
	}
	
	@Override
	public String execute() throws Exception {
		
		return SUCCESS;
	}
	
	/**
	 * 打开列表页面
	 * @return
	 */
	public String openList(){
		pageResult = serviceStudioService.find(serviceStudio, getPage(), getRow());
		setForwardView(LIST_JSP);
		return SUCCESS;
	}

	
	/**
	 * 删除
	 * @return
	 */
	public String delete() {
		serviceStudioService.delete(serviceStudio.getId());
		serviceStudio.setId(null);
		return openList();
	}

	/**
	 * 打开修改页面
	 * @return
	 */
	public String openEdit(){
		serviceStudio = serviceStudioService.findById(serviceStudio.getId());
		
		setForwardView(EDIT_JSP);
		return SUCCESS;
	}

	public String openAdd() {
		setForwardView(ADD_JSP);
		return SUCCESS;
	}
	
	public String add() {
		if(null != serviceStudio){
			serviceStudioService.add(serviceStudio);
		}
		serviceStudio = new ServiceStudio();
		return openList();
	}
	
	public String edit(){
		serviceStudioService.update(serviceStudio);
		serviceStudio = new ServiceStudio();
		return openList();
	}
	
	public ServiceStudio getServiceStudio() {
		return serviceStudio;
	}

	public void setServiceStudio(ServiceStudio serviceStudio) {
		this.serviceStudio = serviceStudio;
	}

	public Result<ServiceStudio> getPageResult() {
		return pageResult;
	}

	public void setPageResult(Result<ServiceStudio> pageResult) {
		this.pageResult = pageResult;
	}







	
	
	
}
